package cn.lyq.card.data.model


class PageInfo {

    var first = 1
    var current = first
    var target: Int? = null
    var total = Int.MAX_VALUE

    fun update(isRefresh: Boolean): Int {
        return if (isRefresh) {
            refresh()
        } else {
            loadMore()
        }
    }

    fun loadMore(): Int {
        target = current + 1
        return current + 1
    }

    fun isRefresh() = target == first

    fun refresh(): Int {
        target = first
        return first
    }

    fun success() {
        target?.let {
            current = it
            target = null
        }
    }

    fun fail() {
        target = null
    }

    fun hasMore() = total > current
}